image: "rust:latest"

stages:
  - build
  - release
  - publish

build:linux:
  stage: build
  before_script:
    - apt-get update -yqq
    - apt-get install -yqq --no-install-recommends pkg-config build-essential libudev-dev musl-tools libssl-dev openssl cmake librdkafka-dev librdkafka++1 librdkafka1
  script:
    - cargo build
    - ls -lha target/debug/
    - mv target/debug/pager_bot target/debug/pager_bot-linux-x86_64-dbg
  artifacts:
    paths:
      - target/debug/pager_bot-linux-x86_64-dbg

build:rpi:
  tags:
    - rpi
  stage: build
  variables:
    RUSTC_WRAPPER: sccache
  script:
    - cargo build
    - ls -lha target/debug/
    - mv target/debug/pager_bot target/debug/pager_bot-armhf-dbg
  artifacts:
    paths:
      - target/debug/pager_bot-armhf-dbg

release:linux:
  stage: release
  before_script:
    - apt-get update -yqq
    - apt-get install -yqq --no-install-recommends pkg-config build-essential libudev-dev musl-tools libssl-dev openssl cmake librdkafka-dev librdkafka++1 librdkafka1
  script:
    - cargo build --release
    - ls -lha target/release/
    - mv target/release/pager_bot target/release/pager_bot-linux-x86_64
  artifacts:
    paths:
      - target/release/pager_bot-linux-x86_64
  rules:
    - if: '$CI_COMMIT_REF_NAME == "master"'
  needs: [ "build:linux" ]


release:rpi:
  tags:
    - rpi
  stage: release
  variables:
    RUSTC_WRAPPER: sccache
  script:
    - cargo build --release
    - ls -lha target/release/
    - mv target/release/pager_bot target/release/pager_bot-armhf
    - upx --best --ultra-brute target/release/pager_bs-armhf
  artifacts:
    paths:
      - target/release/pager_bot-armhf
  rules:
    - if: '$CI_COMMIT_REF_NAME == "master"'
